﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace memcached
{
    /// <summary>
    /// Basic cache store interface.
    /// </summary>
    /// <remarks>Methods return false upon failure, no cache-originating exceptions allowed.</remarks>
    public interface ICache
    {
        /// <summary>
        /// Store item value in cache store.
        /// </summary>
        /// <param name="key">not null</param>
        /// <param name="value">not null</param>
        /// <returns>false if operation failed</returns>
        bool Set(string key, object value);

        /// <summary>
        /// Store item valid for number of seconds.
        /// </summary>
        /// <param name="key">not null</param>
        /// <param name="validFor">seconds, positive</param>
        /// <param name="value">not null</param>
        /// <returns></returns>
        bool Set(string key, int validFor, object value);

        /// <summary>
        /// Store item valid until specified time.
        /// </summary>
        /// <param name="key">not null</param>
        /// <param name="expireAt">in the future</param>
        /// <param name="value">not null</param>
        /// <returns></returns>
        bool Set(string key, DateTime expireAt, object value);

        /// <summary>
        /// Add item value to the store.
        /// </summary>
        /// <param name="key">not null</param>
        /// <param name="validFor">seconds, positive</param>
        /// <param name="value">not null</param>
        /// <returns>false if operation failed or item already exists</returns>
        bool Add(string key, int validFor, object value);

        /// <summary>
        /// tore item valid until specified time.
        /// </summary>
        /// <param name="key">not null</param>
        /// <param name="expireAt"></param>
        /// <param name="value">not null</param>
        /// <returns></returns>
        bool Add(string key, DateTime expireAt, object value);

        /// <summary>
        /// Remove item value from store.
        /// </summary>
        /// <param name="key">not null</param>
        /// <returns>true if operation succeeded, even if item does not exist</returns>
        bool Remove(string key);

        /// <summary>
        /// Same as get, only for convenience.
        /// </summary>
        /// <typeparam name="T">type of value</typeparam>
        /// <param name="key"></param>
        /// <param name="success">true if operation succeeded, also if value is not of type T</param>
        /// <returns>value or null if not found or value of wrong type</returns>
        T Get<T>(string key, out bool success);

        /// <summary>
        /// Return value if available and not expired.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="success">true if operation succeeded</param>
        /// <returns>value or null if not found</returns>
        object Get(string key, out bool success);
    }
}